﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace HRLib
{
    public abstract class TaxEntity : Payable
    {
        private string name;
        private string taxId;

        protected TaxEntity()
        { }

        public TaxEntity(string name, string taxId)
        {
            Name = name;
            TaxId = taxId;
        }

        public string Name
        {
            get { return name; }
            set
            {
                if (value != null &&
                    Regex.IsMatch(value, @"^[\w\s'-]{4,30}$"))
                    name = value;
                else
                    throw new ArgumentException("bad name");
            }
        }

        /// <summary>
        /// Employees Social Security Number.
        /// Must be in the format ddd-dd-dddd.
        /// </summary>
        /// <exception cref="ArgumentException">
        /// Throws ArgumentException on null or bad format
        /// </exception>
        /// 
        
        [Key]
        public string TaxId
        {
            get { return taxId; }
            set
            {
                if (value != null && value.Matches(TaxIdRegex))
                {
                    taxId = value;
                }
                else
                    throw new ArgumentException("Invalid taxid format");
            }
        }

        public abstract string TaxIdRegex { get; }

        /// <summary>
        /// Pay this entity default amount and return total net.
        /// </summary>
        /// <returns></returns>
        public abstract float Pay();
       
    }
}
